package com.s3u4.concurrence;

/**
 * Created by Captain on 27/03/2018.
 */
public class ThreadStateClient {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new MyThead();
        System.out.println("before start : " + thread.getState());

        thread.start();

        System.out.println("before sleep : " + thread.getState());

        Thread.sleep(200);

        System.out.println("so : " + thread.getState());

        synchronized (thread) {
            System.out.println("synchronized outer : " + thread.getState());
            thread.notifyAll();
        }

        thread.join();

        System.out.println("after run " + thread.getState());

    }

    public static class MyThead extends Thread {

        public void run() {
            System.out.println("run : " + super.getState());

            try {
                synchronized (this){
                    System.out.println("synchronized run : " + this.getState());
                    this.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("after wait : " + super.getState());
        }
    }

}
